import {get} from './mapping'

export class Err {
  info = {}

  static instance(e) {
    if (e instanceof Err) {
      return e
    }
    return new Err(e)
  }

  constructor(info) {
    this.info = info
  }

  getCode() {
    return get(this.info, 'code')
  }

  getMsg() {
    return get(this.info, 'msg') || get(this.info, 'message') || JSON.stringify(this.info)
  }
}
